package com.edu.bhu.admin.service.impl;

import java.util.List;

import com.edu.bhu.admin.domain.HouHouseAndImages;
import com.edu.bhu.admin.mapper.HouHouseAndImagesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.HouImagesMapper;
import com.edu.bhu.admin.domain.HouImages;
import com.edu.bhu.admin.service.IHouImagesService;
import com.edu.bhu.common.core.text.Convert;

/**
 * 图片Service业务层处理
 * 
 * @author zhangkeyi
 * @date 2022-02-22
 */
@Service
public class HouImagesServiceImpl implements IHouImagesService 
{
    @Autowired
    private HouImagesMapper houImagesMapper;

    @Autowired
    private HouHouseAndImagesMapper houHouseAndImagesMapper;

    /**
     * 查询图片
     * 
     * @param imagesId 图片主键
     * @return 图片
     */
    @Override
    public HouImages selectHouImagesByImagesId(Long imagesId)
    {
        return houImagesMapper.selectHouImagesByImagesId(imagesId);
    }

    /**
     * 查询图片列表
     * 
     * @param houImages 图片
     * @return 图片
     */
    @Override
    public List<HouImages> selectHouImagesList(HouImages houImages)
    {
        return houImagesMapper.selectHouImagesList(houImages);
    }

    /**
     * 查询图片列表(根据房屋ID)
     *
     * @param houseId 房屋ID
     * @return 图片集合
     */
    public List<HouImages> selectHouImagesListByHouseId(Long houseId)
    {
        return houImagesMapper.selectHouImagesListByHouseId(houseId);
    }

    /**
     * 新增图片
     * 
     * @param houImages 图片
     * @return 结果
     */
    @Override
    public int insertHouImages(HouImages houImages)
    {
        return houImagesMapper.insertHouImages(houImages);
    }

    /**
     * 新增一条图片信息，关联表中存入图片id和房屋id
     *
     * @param houImages 图片
     * @return 结果
     */
    @Override
    public int insertImagesAndHouseId(HouImages houImages, Long houseId) {
        //存储图片路径
        int rows = houImagesMapper.insertHouImages(houImages);
        //存储图片id和房屋id
        HouHouseAndImages hai = new HouHouseAndImages();
        hai.setImagesId(houImages.getImagesId());
        hai.setHouseId(houseId);
        houHouseAndImagesMapper.insertHouHouseAndImages(hai);
        return rows;
    }

    /**
     * 修改图片
     * 
     * @param houImages 图片
     * @return 结果
     */
    @Override
    public int updateHouImages(HouImages houImages)
    {
        return houImagesMapper.updateHouImages(houImages);
    }

    /**
     * 批量删除图片
     * 
     * @param imagesIds 需要删除的图片主键
     * @return 结果
     */
    @Override
    public int deleteHouImagesByImagesIds(String imagesIds)
    {
        return houImagesMapper.deleteHouImagesByImagesIds(Convert.toStrArray(imagesIds));
    }

    /**
     * 删除图片信息
     * 
     * @param imagesId 图片主键
     * @return 结果
     */
    @Override
    public int deleteHouImagesByImagesId(Long imagesId)
    {
        return houImagesMapper.deleteHouImagesByImagesId(imagesId);
    }
}
